<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>修改员工信息</title>
    {% load static %}
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
    <script src="/static/lib/layui/layui.js"></script>

    <link type="text/css" rel="stylesheet" href="/static/css/metroStyle.css">
    <link type="text/css" rel="stylesheet" href="/static/css/treeSelectStyle.css">
    <script src="/static/js/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="/static/js/jquery.ztree.all.js"></script>
    <script type="text/javascript" src="/static/js/treeSelect.2.0.js"></script>
    <script type="text/javascript" src="/static/js/xm-select.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-row layui-col-space10">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">雇员ID<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="user_code" id="user_code" placeholder="请输入雇员代码！(唯一值)" autocomplete="off" class="layui-input"
                       lay-verify="required">
                <input type="text" name="id" id="id" class="layui-input" style="display: none">
            </div>
            </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">雇员姓名<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="username" id="username" placeholder="请输入雇员姓名！" autocomplete="off" class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">身份证号<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="user_id" id="user_id" placeholder="请输入身份证号！" autocomplete="off" class="layui-input"
                       lay-verify="required|identity">
            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">手机号<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="user_mobile" id="user_mobile" placeholder="请输入手机号码" autocomplete="off" class="layui-input"
                       lay-verify="required|phone">
            </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">所属部门<span style="color: red">*</span></label>
            <div class="layui-input-block" name="dept" id="dept">

            </div>
        </div>
            <div class="layui-inline layui-col-md6">
                <label class="layui-form-label">角色<span style="color: red">*</span></label>
                <div class="layui-input-block" id="role" name="role">

                </div>
            </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
            <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">邮箱<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="email" id="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input"
                       lay-verify="required|email">
            </div>
        </div>
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">岗位<span style="color: red">*</span></label>
            <div class="layui-input-block" id="job" name="job">

            </div>
        </div>
        </div>
        <div class="layui-row layui-col-space10" style="padding-top: 10px;">
        <div class="layui-inline layui-col-md6">
            <label class="layui-form-label">是否签字<span style="color: red">*</span></label>
                <div class="layui-input-block">
                    <input type="checkbox" name="is_sign" id="is_sign" title="Y/N">
                </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" placeholder="请输入备注内容" class="layui-textarea"></textarea>
            </div>
        </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary" id="close">关闭</button>
            </div>
        </div>
    </form>
</div>
<!--js逻辑-->

<script type='text/javascript'>
    var data1;
    function child(d) {
        data1 = d;
    layui.use(["form", "okUtils","jquery", "okLayer"], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var okUtils = layui.okUtils;
        var okLayer = layui.okLayer;
        okLoading.close();
        $('#id').val(data1.id);
        $('#user_code').val(data1.user_code);
        $('#username').val(data1.username);
        $('#user_id').val(data1.userid);
        $('#user_mobile').val(data1.user_mobile);
        $('#dept').val(data1.dept);
        $('#dept_id').val(data1.dept_id);
        $('#role').val(data1.role);
        $('#email').val(data1.email);
        $('#remark_describe').val(data1.remark_describe);
        if(data1.is_sign==0){
            $.each($("input[id='is_sign']"),function (i,e) {
                $(e).prop("checked",true);
                form.render();
            });
        }
        // 下拉框数据回显
        var demo3 = xmSelect.render({
                el: '#dept',
                name:'dept',
            radio: true,
                model: {label: {type: 'text'}},
                initValue:data1.dept_id,
            prop:{
	            name:'dept_name',
                value:'id',
            },
                tree: {
                    show: true,
                    strict: true,
                },
                height: 'auto',
                data() {
                    return []
                }
            });
            $.ajax({
                url: "{% url 'config:depts_list1' %}",
                type: "GET",
                success: function (ret) {
                    var node = ret.data;
                    demo3.update({
                        data: node,
                        autoRow: true,
                        iconfont: {
                            parent: 'hidden',
                        }
                    })
                },
                error: function () {
                }
            });
        // 这里得把switch的状态弄对，不然，如果他创建就停用，数据就传不过去了
        form.on("submit(edit)", function (data) {
            if(data.field.is_sign==="on"){
                data.field.is_sign=0;
            }else{
                data.field.is_sign=1;
            }
            okUtils.ajax("/users/users_edit/" + data.field.id, "post", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
                    parent.layui.table.reload('tableId');
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                // 这里已经有提示了
            });
            return false;
        });
        $("#close").click(function () {
            let index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
            parent.layui.table.reload('tableId');
            parent.layer.close(index);
        });
    })};
</script>
<!--以下用于搞定多选下拉框数据回显-->
<script type='text/javascript'>
    var demo1 = xmSelect.render({
        el: '#role',
        name:'role',
        language: 'zn',
        toolbar: {show: true},
        data: []
    });
    $.ajax({
        url: "{% url 'users:users_roles' %}",
        type: "GET",
        success: function (ret) {
            var node = ret;
            var nodes = [];
            $.each(node.data, function (k, v) {
                nodes.push({
                    value: v.value,
                    name: v.name,
                    selected: v.selected
                });
            });
            $.each(nodes, function (l, j) {
                $.each(data1.roles_id, function (o, p) {
                    if (j.value === p) {
                        j.selected = true
                    }
                })
            });
            demo1.update({
                data: nodes,
                autoRow: true,
            })
        },
        error: function () {
        }
    });
</script>
<script type='text/javascript'>
    var demo2 = xmSelect.render({
        el: '#job',
        name:'jobs',
        language: 'zn',
        toolbar: {show: true},
        filterable: true,
        paging: true,
        pageSize: 3,
        data: []
    });
    $.ajax({
        url: "{% url 'config:jobs_list1' %}",
        type: "GET",
        success: function (ret) {
            var node = ret;
            var nodes = [];
            $.each(node.data, function (k, v) {
                nodes.push({
                    value: v.id,
                    name: v.job_name,
                    selected: v.selected
                });
            });
            $.each(nodes, function (l, j) {
                $.each(data1.job_id, function (o, p) {
                    if (j.value === p) {
                        j.selected = true
                    }
                })
            });
            demo2.update({
                data: nodes,
                autoRow: true,
            })
        },
        error: function () {
        }
    });
</script>
</body>
</html>
